package tianrun.ziguan.api.calculate.config.controller.template;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tianrun.ziguan.api.calculate.config.dto.request.ModulesDetailBody;
import tianrun.ziguan.api.calculate.config.dto.request.ModulesSaveBody;
import tianrun.ziguan.api.calculate.config.service.template.module.ModulesService;
import tianrun.ziguan.api.calculate.config.utils.HttpResponseTools;
import tianrun.ziguan.api.common.core.base.ResultBody;

import javax.validation.Valid;

@RestController
@RequestMapping("/modules")
@Api(tags = "组件操作")
public class ModulesController {

    private final ModulesService modulesService;

    public ModulesController(ModulesService modulesService) {
        this.modulesService = modulesService;
    }

    @ApiOperation(value = "模板或资产-组件保存")
    @ApiResponses({@ApiResponse(code = 200, message = "ok")})
    @PostMapping("/save")
    public ResponseEntity<ResultBody<ModulesSaveBody>> save(@RequestBody ModulesSaveBody body) {
        return HttpResponseTools.good(ResultBody.of(modulesService.save(body)));
    }


    @ApiOperation(value = "模板或资产-组件详情")
    @ApiResponses({@ApiResponse(code = 200, message = "ok")})
    @PostMapping("/detail")
    public ResponseEntity<ResultBody<ModulesSaveBody>> detail(@Valid @RequestBody ModulesDetailBody body) {
        return HttpResponseTools.good(ResultBody.of(modulesService.detail(body)));
    }
}
